//
//  SaveViewController.m
//  NetWorkSave
//
//  Created by 苗旭萌 on 15/11/17.
//  Copyright © 2015年 苗旭萌. All rights reserved.
//

#import "SaveViewController.h"
#import <Parse/Parse.h>

@interface SaveViewController ()

@end

@implementation SaveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.dic[@"url"]]];
    NSLog(@"============%@",self.dic[@"url"] );
    [webView loadRequest:request];
    
   // NSLog(@"self.dic===== %@", self.dic);
    
    [self.view addSubview:webView];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveButton)];

}

- (void)saveButton
{
    // 保存 创建表
    PFObject *object = [[PFObject alloc] initWithClassName:@"message"];
    [object setObject:self.dic[@"title"] forKey:@"title"];
    
    [object setObject:self.dic[@"imgsrc"] forKey:@"image"];
    
    [object setObject:self.dic[@"url"] forKey:@"url"];
    
   
  
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    [object setObject:[user objectForKey:@"userID"] forKey:@"uid"];
    [object setObject:[user objectForKey:@"userName"] forKey:@"uid"];
    [object saveInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
        
        if (succeeded) {
            NSLog(@"收藏成功");
        }
    
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
